<template>  
    <view class="container">  
		
		<view class="user-section">
			<image class="bg" src="/static/info_bg.png" ></image>
			<view class="user-info-box">
				<view class="portrait-box" >
					<image class="portrait" :src="userInfo.avatar ? userInfo.avatar.url + '?rand=' + Math.random() : '/static/missing-face.png'"></image>
				</view>
				<view class="info-box">
					<text class="username">{{userInfo.nickname || '游客'}}</text>
					<!-- <text class="user-level">{{userInfo.group.group_name || ''}}</text> -->
				</view>
				
			</view>
		</view>
		
		<view 
			class="cover-container"
			:style="[{
				transform: coverTransform,
				transition: coverTransition
			}]"
			@touchstart="coverTouchstart"
			@touchmove="coverTouchmove"
			@touchend="coverTouchend"
		>
			<image class="arc" src="/static/arc.png"></image>
			
			<view class="tj-sction" >
				<!-- <view class="tj-item" @click="navTo('/pages/user/setmeal/setmeal')">
					<view ><image class="vip-image" :src=" userInfo.group.group_id ? '/static/vip_'+(userInfo.group.group_id - 1)+'.png' : '/static/vip_0.png'"></image></view>
					<text>{{userInfo.group.group_name || ''}}</text>
				</view> -->
				<view class="tj-item">
					<text class="num">{{userInfo.money||'0.00'}}</text>
					<text>余额</text>
				</view>
				<view class="tj-item" @click="navTo('/pages/user/scorelog/scorelog')">
					<text class="num">{{userInfo.integral||0}}</text>
					<text>积分</text>
				</view>
				<view class="tj-item">
					<text class="num">{{userInfo.brokerage_price||'0.00'}}</text>
					<text>佣金</text>
				</view>
			</view>
			<!-- 浏览历史 -->
			<view class="history-section icon">
				<u-cell-group :border="false">
					<u-cell title="我的团队" @click="navTo('/pages/user/team/index')" :isLink="true">
						<u-icon slot="icon" name="heart-fill"></u-icon>
					</u-cell>
					<u-cell title="订单管理" @click="navTo('/pages/user/order/index')" :isLink="true">
						<u-icon slot="icon" name="order"></u-icon>
					</u-cell>
					<u-cell title="结算管理" @click="navTo('/pages/user/daily/index')" :isLink="true">
						<u-icon slot="icon" name="rmb"></u-icon>
					</u-cell>
					<u-cell title="用户设置" @click="navTo('/pages/user/index/userinfo')" :isLink="true">
						<u-icon slot="icon" name="setting-fill"></u-icon>
					</u-cell>
				</u-cell-group>
				
				
			</view>
			
			<view class="login-out-but">
				<u-button type="error" text="退出登录" @click="loginOut"></u-button>
			</view>
		</view>
			
		
    </view>  
</template>  
<script>  
	import { mapGetters } from 'vuex'
	let startY = 0, moveY = 0, pageAtTop = true;
   export default {
		components:{},
		data(){
			return {
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
			}
		},
       computed: {
			...mapGetters(['userInfo'])
       },
		onLoad(){
			this.getUserInfo();
		},
        methods: {
			getUserInfo(){
				this.$store.dispatch('user/userInfo');
			},

			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(_url){
				console.log(_url)
				uni.$u.route({
					url:_url
				}); 
			}, 
	
			/**
			 *  会员卡下拉和回弹
			 *  1.关闭bounce避免ios端下拉冲突
			 *  2.由于touchmove事件的缺陷（以前做小程序就遇到，比如20跳到40，h5反而好很多），下拉的时候会有掉帧的感觉
			 *    transition设置0.1秒延迟，让css来过渡这段空窗期
			 *  3.回弹效果可修改曲线值来调整效果，推荐一个好用的bezier生成工具 http://cubic-bezier.com/
			 */
			coverTouchstart(e){
				if(pageAtTop === false){
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e){
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if(moveDistance < 0){
					this.moving = false;
					return;
				}
				this.moving = true;
				if(moveDistance >= 80 && moveDistance < 100){
					moveDistance = 80;
				}
		
				if(moveDistance > 0 && moveDistance <= 80){
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend(){
				if(this.moving === false){
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			},
			loginOut(){
				this.$store.dispatch('user/logOut').then(res=>{
					uni.$u.toast('退出登录成功！');
					uni.$u.route({
						url:'pages/login/login',
						params:{}
					})
				}).catch(err=>{
					uni.$u.toast(`页面错误！${JSON.stringify(err)}`);
				});
			}
        }  
		,onPullDownRefresh() {
			//下拉刷新
			 // this.getUserInfo();
			 uni.stopPullDownRefresh();
		},
	}  
</script>  
<style lang='scss'>
	%flex-center {
	 display:flex;
	 flex-direction: column;
	 justify-content: center;
	 align-items: center;
	}
	%section {
	  display:flex;
	  justify-content: space-around;
	  align-content: center;
	  background: #fff;
	  border-radius: 10rpx;
	}
	.vip-image{
		width: 60rpx;
		height: 60rpx;
	}
	.user-section{
		height: 420rpx;
		padding: 100rpx 30rpx 0;
		position:relative;
		.bg{
			position:absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			filter: blur(1px);
			opacity: 0.8;
		}
	}
	.user-info-box{
		height: 180rpx;
		display:flex;
		align-items:center;
		position:relative;
		z-index: 1;
		.portrait{
			width: 130rpx;
			height: 130rpx;
			border:5rpx solid #fff;
			border-radius: 50%;
		}
		.username{
			font-size: 38rpx;
			color: #303133;
			margin-left: 20rpx;
		}
		.user-level{
			margin-left:10rpx;
			font-size: 24rpx;
		}
	}

	.vip-card-box{
		display:flex;
		flex-direction: column;
		color: #f7d680;
		height: 240rpx;
		background: linear-gradient(to left, rgba(0,0,0,.7), rgba(0,0,0,.8));
		border-radius: 16rpx 16rpx 0 0;
		overflow: hidden;
		position: relative;
		padding: 20rpx 24rpx;
		.card-bg{
			position:absolute;
			top: 20rpx;
			right: 0;
			width: 380rpx;
			height: 260rpx;
		}
		.b-btn{
			position: absolute;
			right: 20rpx;
			top: 16rpx;
			width: 132rpx;
			height: 40rpx;
			text-align: center;
			line-height: 40rpx;
			font-size: 22rpx;
			color: #36343c;
			border-radius: 20px;
			background: linear-gradient(left, #f9e6af, #ffd465);
			z-index: 1;
		}
		.tit{
			font-size: 30rpx;
			color: #f7d680;
			margin-bottom: 28rpx;
			.yticon{
				color: #f6e5a3;
				margin-right: 16rpx;
			}
		}
		.e-b{
			font-size: 24rpx;
			color: #d8cba9;
			margin-top: 10rpx;
		}
	}
	.cover-container{
		margin-top: -150rpx;
		padding: 0 30rpx;
		position:relative;
		background-color: #f5f5f5;
		padding-bottom: 20rpx;
		height: calc(100vh - 420rpx);
		.arc{
			position:absolute;
			left: 0;
			top: -34rpx;
			width: 100%;
			height: 36rpx;
		}
	}
	.tj-sction{
		@extend %section;
		.tj-item{
			@extend %flex-center;
			flex-direction: column;
			height: 140rpx;
			font-size: 24rpx;
			color: #75787d;
		}
		.num{
			font-size: 32rpx;
			color: #303133;
			margin-bottom: 8rpx;
		}
	}
	.order-section{
		@extend %section;
		padding: 28rpx 0;
		margin-top: 20rpx;
		.order-item{
			@extend %flex-center;
			width: 120rpx;
			height: 120rpx;
			border-radius: 10rpx;
			font-size: 24rpx;
			color: #303133;
		}
		.yticon{
			font-size: 48rpx;
			margin-bottom: 18rpx;
			color: #fa436a;
		}
		.icon-shouhoutuikuan{
			font-size:44rpx;
		}
	}
	.history-section{
		padding: 30rpx 0 0;
		margin-top: 20rpx;
		background: #fff;
		border-radius:10rpx;
		.sec-header{
			display:flex;
			align-items: center;
			font-size: 28rpx;
			color: #303133;
			line-height: 40rpx;
			margin-left: 30rpx;
			.yticon{
				font-size: 44rpx;
				color: #5eba8f;
				margin-right: 16rpx;
				line-height: 40rpx;
			}
		}
		.h-list{
			white-space: nowrap;
			padding: 30rpx 30rpx 0;
			image{
				display:inline-block;
				width: 160rpx;
				height: 160rpx;
				margin-right: 20rpx;
				border-radius: 10rpx;
			}
		}
		
		
	}
	.login-out-but{
		/* margin-top:60rpx; */
		position: fixed;
		left:0;
		right:0;
		bottom: 140rpx;
	}
</style>